package io;

import java.io.*;

/**
 * @Author Justin Parker
 * @Date 2024/7/16 0016 16:33
 * @Version 1.0
 */
public class ObjectOutputStreamDemo01 {
    public static void main(String[] args) throws IOException, ClassNotFoundException {

        Message msg1 = new Message(1, "传奇病了", "做了个小手术");
        Message msg2 = new Message(2, "传奇快好了", "估计下周上课");
            //1.构建流对象
            ObjectOutputStream oos =
                    new ObjectOutputStream(
                            new BufferedOutputStream(
                                    new FileOutputStream("msg.txt")));
            //2.写对象（序列化）
            oos.writeObject(msg1);
            oos.writeObject(msg2);
            System.out.println("序列化ok");


//        ObjectInputStream ois =
//                new ObjectInputStream(
//                        new BufferedInputStream(
//                                new FileInputStream("msg.txt")));
//
//         Message msg3 =(Message) ois.readObject();
//         Message msg4 =(Message) ois.readObject();
//         System.out.println(msg3);
//        System.out.println(msg4);
//        System.out.println("反序列化ok");
            //关闭流对象
            oos.close();


    }
}
